package controller;

import java.util.List;
import java.util.UUID;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import pojo.Customer;
import service.CustomerManager;
import service.impl.CustomerManagerFactory;

@Controller
@RequestMapping(value="/customer")
public class CustomerController {
	
	private CustomerManager manager;
	
	public CustomerController() {
		manager = CustomerManagerFactory.getInstance();
	}

	@RequestMapping(value="/add", method=RequestMethod.POST)
	public String addCustomer(Customer c) {
		c.setId(UUID.randomUUID().toString());
		manager.addCustomer(c);
		return "redirect:list";
	}
	
	@RequestMapping(value="/list")
	public String listCustomer(Model m) {
		List<Customer> customers = manager.findAllCustomers();
		m.addAttribute("customers", customers);
		return "list";
	}
}
